package com.mate.cloud;

import com.mate.cloud.config.MessagePropertiesConfig;
import com.mate.cloud.config.PropertyConfig;
import com.mate.cloud.exception.UserExceptionCode;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.MessageFormat;
import java.util.Properties;
import java.util.Set;

/**
 * 加载 properties 文件和打印测试
 *
 * @author: MI
 * @email: 448341911@qq.com
 * @createTime: 2025/1/28 12:01
 * @updateUser: MI
 * @updateTime: 2025/1/28 12:01
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Slf4j
@SpringBootTest
public class SpringBootMessagePropertiesApplicationTest {

    /**
     * 加载配置文件并打印测试
     */

    @Test
    public void loadMessageTest() {

        MessagePropertiesConfig propertiesConfig = new MessagePropertiesConfig();
        Properties properties = propertiesConfig.loadAndPrintProperties();


        // 获取某个属性并打印
        final String key = String.valueOf(UserExceptionCode.PARAMS_ERROR.getCode());
        String property = properties.getProperty(key);

        log.info(MessageFormat.format("获取属性值为：{0}",property));

    }


    /**
     * 占位符替换测试
     */
    @Test
    public void loadMessageFormatTest() {

        final String key = String.valueOf(UserExceptionCode.EMAIL_ALREADY_REGISTER.getCode());
        // 获取某个属性并打印
        String message= PropertyConfig.getProperty(key,"448349111@qq.com");

        log.info(MessageFormat.format("获取属性值为：{0}", message));
        log.info("获取属性值为：{}",message);
    }

}